package com.shizhanzhe.zxbapp.task.newshare;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.shizhanzhe.zxbapp.R;


/**
 * Created by zz9527 on 2019/5/8.
 */
public class Webview extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_adver);
        WebView web = findViewById(R.id.web);
        TextView title = findViewById(R.id.web_title);
        int type = getIntent().getIntExtra("type", 0);
        if (type==1){
            title.setText("广告");
        }else if (type==2){
            title.setText("幸运大转盘");
        }
        findViewById(R.id.backarea).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        final ProgressBar pg1 = findViewById(R.id.progressBar);
        WebSettings webSettings = web.getSettings();
        if (webSettings == null) return;
        // 支持 Js 使用
        webSettings.setJavaScriptEnabled(true);
        web.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView webView, int newProgress) {
                if (newProgress == 100) {
                    //加载完网页进度条消失
                    pg1.setVisibility(View.GONE);
                } else {
                    //开始加载网页时显示进度条
                    pg1.setVisibility(View.VISIBLE);
                    //设置进度值
                    pg1.setProgress(newProgress);
                }
            }
        });
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        web.loadUrl(getIntent().getStringExtra("url"));
    }
}
